package com.xlongwei.todays.dao;

import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;
import org.noear.solon.data.annotation.Cache;
import org.noear.solon.data.annotation.CacheRemove;
import org.noear.solon.data.annotation.Transaction;
import com.xlongwei.todays.config.MySqlUtils;
import com.xlongwei.todays.model.Extra;

@Component
public class ExtraDao {
    @Inject
    MySqlUtils sqlUtils;

    @Transaction
    @CacheRemove(keys = "extra.${}")
    public Integer create(Extra row) {
        assert row.getTodoid() != null;
        return sqlUtils.sql("insert into t_extra(todoid,remark) values(?,?)", row.getTodoid(),
                row.getRemark()).update();
    }

    @Transaction
    @CacheRemove(keys = "extra.${row.todoid}")
    public Integer update(Extra row) {
        assert row.getTodoid() != null;
        return sqlUtils
                .sql("update t_extra set remark=? where todoid=?", row.getRemark(), row.getTodoid())
                .update();
    }

    @Cache(key = "extra.${todoid}")
    public Extra retrieve(Integer todoid) {
        return sqlUtils.sql("select todoid,remark from t_extra where todoid=?", todoid).queryRow(Extra.class);
    }
}
